import { reactive } from "vue"

export const useCommand = () => {
    const state = reactive({
        currnetIndex: -1,
        operateQueue: [], // 存放所有的操作命令
        commands: {}, // 存放所有的指令和执行功能的映射
        commandArray: [] // 存放所有的指令
    })

    const register = (command) => {
        state.commandArray.push(command)
        state.commands[command.name] = () => {
           return command.execute().redo()
        }
    }

    // 注册命令
    register({
        name: 'redo',
        keyboard: 'ctrl+y',
        execute: () => ({
            redo: () => {
                console.log('redo')
            }
        })
    })

    register({
        name: 'undo',
        keyboard: 'ctrl+z',
        execute: () => ({
            redo: () => {
                console.log('undo')
            }
        })
    })

    return state
}